package com.ymatou.iapi.im.testcase;

import com.ymatou.iapi.im.parameter.GetGlobalMessageCountBean;
import com.ymatou.iapi.im.parameter.SendMessageToBuyerBean;
import com.ymatou.iapi.im.parameter.SendMessageToSellerBean;
import com.ymatou.iapi.im.service.GetGlobalMessageCountCall;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymttest.business.service.ImCallService;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.sqlwapper.ImDefaultWapper;
import com.ymttest.utils.EnvSetup;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
*获取消息未读数（全球优选）
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetGlobalMessageCount{
	private static GetGlobalMessageCountBean getglobalmessagecountBean;
	private static GetGlobalMessageCountCall getglobalmessagecountCall;
	private static Integer sellerId = Integer.valueOf(EnvSetup.getData("globalSellerId"));
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取消息未读数（全球优选）");
	}

	@Before
	public void caseUp() {
		getglobalmessagecountBean=new GetGlobalMessageCountBean();
		getglobalmessagecountCall=new GetGlobalMessageCountCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getglobalmessagecountCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetGlobalMessageCount_01() {
		Logger.start(true,"获取全球优选未读记录,买家向优选买手发送消息");
		try {
			UserRegisterInfoRequestDtoBean regbean1 = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc1 = JUserCallService.UserRegisterInfoRequestDtoCall(regbean1);
			Integer userId = urrc1.getUserid();

			SendMessageToSellerBean sendMessageToSellerBean = ImCallService.initSendMessageToSellerBean(userId,sellerId,"我是买家");
			ImCallService.SendMessageToSeller(sendMessageToSellerBean);
			ImCallService.SendMessageToSeller(sendMessageToSellerBean);
			ImCallService.SendMessageToSeller(sendMessageToSellerBean);
			getglobalmessagecountBean.setUserId(sellerId);
			getglobalmessagecountCall.setData(getglobalmessagecountBean);
			getglobalmessagecountCall.callService();
			//优选买手是固定的  未读数不好校验
			Logger.verifyEquals("Success",getglobalmessagecountCall.getString("Status"),"验证Status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}


	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetGlobalMessageCount_02() {
		Logger.start(true,"获取全球优选未读记录，优选买手向买家发送消息");
		try {
			UserRegisterInfoRequestDtoBean regbean1 = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc1 = JUserCallService.UserRegisterInfoRequestDtoCall(regbean1);
			Integer userId = urrc1.getUserid();

			SendMessageToBuyerBean sendMessage = ImCallService.initSendMessageToBuyerBean(sellerId,userId,"我是买家");
			ImCallService.SendMessageToBuyer(sendMessage);
			ImCallService.SendMessageToBuyer(sendMessage);
			ImCallService.SendMessageToBuyer(sendMessage);
			ImCallService.SendMessageToBuyer(sendMessage);
			Thread.sleep(5000);
			getglobalmessagecountBean.setUserId(userId);
			getglobalmessagecountCall.setData(getglobalmessagecountBean);
			getglobalmessagecountCall.callService();
			Logger.verifyEquals("Success",getglobalmessagecountCall.getString("Status"),"验证Status");
			Logger.verifyEquals(Integer.parseInt(getglobalmessagecountCall.getString("Result")),4,"验证未读数");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetGlobalMessageCount_03() {
		Logger.start(true,"获取全球优选未读记录，买手不合法");
		try {
			getglobalmessagecountBean.setUserId(-1);
			getglobalmessagecountCall.setData(getglobalmessagecountBean);
			getglobalmessagecountCall.callService();
			Logger.verifyEquals("ParameterError",getglobalmessagecountCall.getString("Status"),"验证Status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetGlobalMessageCount_04() {
		Logger.start(true,"获取全球优选未读记录，用户不存在");
		try {
			getglobalmessagecountBean.setUserId(000123);
			getglobalmessagecountCall.setData(getglobalmessagecountBean);
			getglobalmessagecountCall.callService();
			Logger.verifyEquals("BussinessError",getglobalmessagecountCall.getString("Status"),"验证Status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}


}